import java.util.PriorityQueue;
import java.util.Queue;

class Solution {
    public static long maxKelements(int[] nums, int k) {
        Queue<Integer> queue = new PriorityQueue<>((a, b) -> (b - a));
        for (int num : nums) {
            queue.add(num);
        }
        long res = 0;
        while (k-- > 0) {
            Integer val = queue.peek();
            if (val != null) {
                res += val;
                queue.poll();
                int tmp = val / 3;
                queue.add(tmp >= val ? tmp : tmp + 1);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(maxKelements(new int[]{1,10,3,3,3}, 3));
    }
}